
public class Main {
    //调用20个线程输出0~20后，输出OK
    public static void main(String[] args) throws InterruptedException{
        Thread[] threads = new Thread[20];
        for (int i = 0; i < threads.length; i++) {
            final int n = i;
            threads[i] = new Thread(new Runnable() {
                @Override
                public void run() {
                    System.out.print(n + " ");
                }
            });
        }
        for ( Thread t : threads) {
            t.start();
        }
        for ( Thread t : threads) {
            t.join();//等待
        }

        System.out.println("OK");

    }
}
